<script>
import {defineComponent} from 'vue'
import axios from "axios";
import {login, loginUser, logout} from "@/api/login";


export default defineComponent({
    name: "headerModule",
    data(){
        return{
            userInfo: {},
            arrList:'',
            isLogin: true,
            courseList: '',
            visible: false,
            formInline: {
                username: '',
                password: '',
                rememberMe: false
            },
        }
    },
    methods:{
        logout1(){
            logout().then(res =>{
                console.log(res)
                if (res.code===0){
                    this.isLogin = true
                    this.userInfo = {}
                }
            })
        },
        showModal() {
            this.visible = true;
        },
        handleOk(e) {
            console.log(e);
            this.visible = false;
        },
        // 表单
        handleSubmit() {
            login(this.formInline).then(res => {
                console.log(res)
                if (res.code === 0) {
                    // 1 关闭弹框
                    this.visible = false;
                    // 2 提示
                    this.$message.success('登录成功')
                    // 3 显示头像
                    this.isLogin = false
                    // 4 渲染数据
                    this.userInfo = res.userInfo
                } else {
                    this.$message.error(res.msg)
                }
            })
        }
    },
    created() {
        loginUser().then(res => {
            console.log(res)
            if (res.code === 0) {
                // 3 显示头像
                this.isLogin = false
                // 4 渲染数据
                this.userInfo = res.data
            } else {
                this.userInfo = {}
            }
        })
        axios.post('http://1.117.81.216:8087/weChat/applet/subject/list',
            {'enable':"1"}).then(res=>{
            this.arrList = res.data.rows
        })


    }
})
</script>

<template>
<div>
    <div class="top-title">
        <div class="title">
            <img
                    class="title-img"
                    src="https://course.myhope365.com/img/logo-text.321d0dc2.png"
                    alt=""
            />
        </div>
        <!-- 顶部内容 -->
        <div class="navigation">
            <div class="left-nav">
                <ul>
                    <li>首页</li>
                    <li id="course">
                        <a-dropdown class="dor">
                            <a  style="color: white" class="ant-dropdown-link" @click="e => e.preventDefault()">
                                课程分类
                                <a-icon type="down"/>
                            </a>
                            <a-menu slot="overlay">
                                <a-menu-item v-for="(item) in arrList" :key='item.subjectId'>
                                    <a target="_blank" rel="noopener noreferrer" href='hppt://www.akipay.com'>{{item.subjectTitle}}</a>
                                </a-menu-item>
                            </a-menu>
                        </a-dropdown>
                    </li>
                    <li>教学管理云平台</li>
                </ul>
            </div>
            <span class="center-span">
            <input
                    placeholder="搜索课程~"
                    type="text"
                    size="large"
                    class="input"
            />
            <button>
              <img
                      src=""
                      alt=""
              />
            </button>
          </span>
            <div class="right-login">
                <div class="shopping-cart">
                    <img
                            src=""
                            alt=""
                    />
                </div>
                <div class="login-box">
                    <div class="top-img">开通VIP免费观看全站视频</div>
                    <div v-if="isLogin">
                        <a-button type="primary" @click="showModal">
                            登录/注册
                        </a-button>
                    </div>
                    <div v-else style="font-size: 14px;width: 90px;margin-top: 0px">
                        <a-dropdown>
                            <a class="ant-dropdown-link" @click="e => e.preventDefault()">
                                <a-avatar :src="userInfo.avatarUrl"/>
                                {{ userInfo.nickname }}
                                <a-icon type="down"/>
                            </a>
                            <a-menu slot="overlay">
                                <a-menu-item>
                                    <router-link to="person">个人中心</router-link>
                                </a-menu-item>
                                <a-menu-item>
                                    <a href="javascript:;">我的课程</a>
                                </a-menu-item>
                                <a-menu-item>
                                    <a href="javascript:;">我的订单</a>
                                </a-menu-item>
                                <a-menu-item>
                                    <a href="javascript:;" @click="logout1">退出登录</a>
                                </a-menu-item>
                            </a-menu>
                        </a-dropdown>
                    </div>
                    <a-modal width="350px" v-model="visible" :footer="null" @ok="handleOk">
                        <a-form-model layout="vertical" :model="formInline" @submit="handleSubmit"
                                      @submit.native.prevent>
                            <a-form-model-item>
                                <a-input v-model="formInline.username" placeholder="Username">
                                    <a-icon slot="prefix" type="user"
                                            style="color:rgba(0,0,0,.25)"/>
                                </a-input>
                            </a-form-model-item>
                            <a-form-model-item>
                                <a-input v-model="formInline.password" type="password"
                                         placeholder="Password">
                                    <a-icon slot="prefix" type="lock"
                                            style="color:rgba(0,0,0,.25)"/>
                                </a-input>
                            </a-form-model-item>
                            <a-form-model-item>
                                <a-button
                                    size="large"
                                    class="btn"
                                    type="primary"
                                    html-type="submit"
                                >
                                    Log in
                                </a-button>
                            </a-form-model-item>
                        </a-form-model>
                    </a-modal>
                </div>
            </div>
        </div>
    </div>
</div>
</template>

<style scoped lang="less">
* {
    margin: 0;
    padding: 0;
    font-size:16px;
}
a, a:hover, a:visited {
    text-decoration: none;
}
body{
    margin: 0;
    font-size:16px;
}
.ant-btn-primary{
    border-radius: 20px;
    margin-top: -60px;
    color: #35c7de;
    background: #f4f4f4;
    border: none;
    font-weight: 600;
    font-size: 15px;
}
/* 顶部图片 */
.top-title {
    width: 100%;
    height: 295px;
    background: no-repeat
    url(https://course.myhope365.com/img/index-top-bg.564836d0.png);
    background-size: 100% 100%;
}
.top-title > .title {
    width: 1160px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}
.top-title > .title > .title-img {
    width: 212px;
    border: 0;
    margin: 50px 0 50px;
    vertical-align: middle;
}
/* 顶部数据 */
.navigation{
    align-items: center;
    display: flex;
    margin: 0 auto;
    width: 1160px;
    height: 80px;
}
.navigation > .left-nav{
    margin-right: 30px;
    margin-left: 40px;
    color: #fff;
    height: 30px;
    font-weight: 600;
    float: left;
}
.navigation > .left-nav > ul{
    list-style-type: none;
    display: flex;
}
.navigation > .left-nav > ul > li{
    margin-right: 30px;
}
.course{
    position: relative;
}
.course-ul{
    color: black;
    display: none;
    position: absolute;
    z-index: 100;
    list-style-type: none;
    background-color: white;
    padding: 3px;
}
.course-li{
    margin-left: 2px;
    height: 30px;
    line-height: 30px;
    z-index: 100;
}
.course-a{
    font-weight: 300;
    font-size: 15px;
    color: rgb(120, 118, 118);
}
.center-span{
    display: flex;
    margin-left: 280px;
}
.center-span > .input{
    outline: none;
    height: 35px;
    border-radius: 20px;
    float: left;
    width: 250px;
    margin-bottom: 0;
    text-align: inherit;
    padding: 6px 11px;
    font-size: 16px;
    background-color: #fff;
    background-image: none;
    border: 1px solid #d9d9d9;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}
.center-span > button{
    background: transparent;
    border-radius: 20px;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    height: 35px;
    width: 50px;
    border: 1px solid #d9d9d9;
}
.right-login{
    height: 100%;
    font-size: 14px;
    display: flex;
    align-items: center;
    width: 150px;
}
.right-login > .shopping-cart{
    width: 36px;
    height: 36px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 2px 4px 0 rgba(0,0,0,.23);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 10px;
}
.right-login > .login-box{
    cursor: pointer;
    display: flex;
    align-items: center;
    position: relative;
    justify-content: center;
}
.right-login > .login-box > .top-img{
    position: absolute;
    font-size: 10px;
    top: -50px;
    width: 155px;
    height: 41px;
    text-align: center;
    line-height: 30px;
    font-weight: 500;
    background: url();
    background-size: 100%;
    color: #fff;
}
.right-login > .login-box >.btn-log{
    color: rgb(53, 199, 222);
    width: 94px;
    height: 30px;
    background: #fff;
    border-radius: 15px;
    font-weight: 600;
    font-size: 15px;
    text-align: center;
    line-height: 30px;
}
#show {
    width: 30px;
    height: 30px;

}

#show > img {
    width: 30px;
    height: 30px;
}

#dog {
    color: #fff;
    font-weight: 600;
    margin-left: 9px;
}

#dog > div {
    position: relative;
    color: #bc3b3b;
    font-weight: 600;
}

#sonry {
    position: absolute;
    width: 15px;
    height: 10px;
    right: 60px;
    top: 7px;
}

#dogbox {
    position: absolute;
    z-index: 90;
    margin-left: -15px;
    width: 85px;
    height: 100px;
    background-color: rgb(195, 195, 195);
}

#dogbox {
    text-align: center;
    color: rebeccapurple;
}

#dogbox > div {
    margin-bottom: 7px;
}

#dogbox > div:hover {
    color: red;
}

/deep/ .ant-modal-body {
    padding: 40px;
}

.btn {
    margin-top: 0;
    width: 100%;
}
</style>